home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d1 / batchlrn.arc / IF.HLP < prev    next >
Text File  |  1991-06-17  |  6KB  |  83 lines

  1. |---------------B A T C H L R N  H E L P  S Y S T E M-----------------|
  2. |command: IF                                                          |
  3. |use: The IF subcommand allows you to direct the decision-making pro- |
  4. | cess in batch processing files (referred to as statement "testing").|
  5. |                                      |
  6. |how: Type: IF <condition> <DOS or batch command> [see*&**NEXT]       |
  7. | **<command> == Any legal DOS command or batch file subcommand       |
  8. | *<condition> == One of three tests that yield a true or false re-   |
  9. | sult:                                      |
  10. |               1. The ERRORLEVEL of a program (see below)            |
  11. |               2. Two strings that are equivalent or the same.       |
  12. |               3. A file that exists in the CURRENT directory.       |
  13. |                                                                     |
  14. |explanation:The IF command tests for true or false. IF true, it per- |
  15. | forms the command. IF NOT true,it skips the command and goes to the |
  16. | NEXT line in the batch processing file. You can "test" SEVERAL lines|
  17. | one after the other, so that if the first line is not true the batch|
  18. | file moves to the next "testing" line. This will continue until no  |
  19. | more tests are left or a TRUE statement directs a command(like GOTO)|
  20. |                                                              |
  21. |examples: Refer to BATSEEK.BAT to see the file testing for the pres- |
  22. | ence of.EXE &.COM files, the GOTO command & the failure to meet the |
  23. | presence of the %1 variable (you JUST typed BATSEEK, nothing else). |
  24. |actual pgm:The following batch file can be used to establish a pass- |
  25. | word for running a program. The batch file is named PASSWRD.BAT and |
  26. | calls up a fictitious program name MY.COM:                          |
  27. |    {NOTE:[fghev xcvw] == our notes  & 0) represents EDLIN line #s}  |
  28. | 1) ECHO OFF       [allows messaging in file w/next cmnd.            |
  29. | 2) CLS            to clear the ECHO OFF from the screen]            |
  30. | 3) IF %1 == ABC GOTO FINE [this is the label][IF TRUE,JUMP occurs]  |
  31. | 4) ECHO BAD PASSWORD--ENDING [msg./appears if NO ABC,then NO JUMP]  |
  32. | 5) GOTO END [ALWAYS end EA.cmnd.sequencing with this cmnd/label]    |
  33. | 6) :FINE  [first label to wh/file JUMP occurs when statement TRUE]  |
  34. | 7) ECHO YOU'RE IDENTIFIED--STARTING CMD.SEQUENCE [msg/1st part:GOOD]|
  35. | 8) MY   [the command portion of the :GOOD command sequence]         |
  36. | 9) GOTO END [remember, end each command sequence this way]          |
  37. |10) :END [the second JUMP label--remember labels direct traffic]     |
  38. |11) ECHO I'VE DONE MY JOB!--RETURNING TO CURRENT DRIVE [end msg.]    |
  39. |elucidation:Look at the response of the computer to various cmds.    |
  40. | First a BAD password. At the prompt type: PASSWRD XYZ [xyz==%1]     |
  41. | The computer tests for TRUE [it's NOT since %1 doesn't == ABC] and  |
  42. | [goes to NEXT line] performs NEXT command, which is to display msg: |
  43. |                       BAD PASSWORD--ENDING                          |
  44. | Now, a GOOD password. At the prompt type: PASSWRD ABC [now,abc==%1] |
  45. | The computer tests for TRUE [it IS since %1 == ABC] and performs the|
  46. | GOTO :FINE command and performs JUMP to label :FINE. P.C.then does  |
  47. | what you told it to do after the label :FINE and performs the comm- |
  48. | and prompt "MY" after acknowledging the passwrod with a message. Af-|
  49. | ter MY performs you are returned to :END and sign off. Note the cmd.|
  50. | MY will not appear because echo is off and you didn't call for ECHO.|
  51. | The :END label displays the final message, but there is no require- |
  52. | ment that additional lines appear after end.                        |
  53. |                                          |
  54. |NOTES: Unlike programming languages, which allow many logical tests  |
  55. | in an IF statement, the batch IF statement is limited to only the   |
  56. | three named above. TO FURTHER EXPLAIN:                              |
  57. |  >Condition 1:ERRORLEVEL is a number that indicates to DOS whether  |
  58. |  the last program run was succesful. A zero (0) indicates a good    |
  59. |  run, anything above zero indicates an error condition (only DOS    |
  60. |  commands BACKUP and RESTORE have an exit code). You probably WILL  |
  61. |  NOT have use for this feature often. There ARE commercial programs |
  62. |  which make extensive use of ERRORLEVEL.These allow PC-User response|
  63. |  and other features like alternate selection via Yes & No or selec- |
  64. |  tion of numbers and/or letters (1,2,3,4 OR a,b,c,d, etc.).         |
  65. |                                                                     |
  66. |  >Condition 2:String comparison is indicated by a double equal sign:|
  67. |                        String1 == String22                          |
  68. | This compares the two strings. It is often used with parameters and |
  69. | markers to check for a particular entry. For example:               |
  70. | IF %1 == 40  typing:"MODE C40" checks parameter one for 40 and, if  |
  71. | if the condition is TRUE [%1 == 40] it changes the display to 40-   |
  72. | columns wide. [SEE batch files on this disk for examples/study them]|
  73. |                                                                     |
  74. |   >Condition 3:The logical test for checking for the existence of a |
  75. | file has as its format: EXIST C:<filename.ext>                      |
  76. | You can use this test to check and see if a file is in C: drive     |
  77. | (as in the example). EXIST B:<filename.ext> might be used to check  |
  78. | to see if B: drive has a DOS disk in the drive. Explore other uses  |
  79. | after examining files on this disk with "EXIST". Note: you cannot   |
  80. | use pathnames for checking on a file's existence.                   |
  81. |                                          |
  82. |----------------- T  I  M  E  M  A  S  T  E  R  ---------------------|
  83.